#! /bin/bash

#----------------------------------
#define all the stock information 
#
#-----------------------------------

# wget http://table.finance.yahoo.com/table.csv?s=600090.ss
# wget http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx/getStockInfoByCode?theStockCode=sh600090

   
 sqlplus stock/stock@ORCL << end_sql
  def p1=$1
  set ver off
  delete from stockinfo;
  exit
end_sql
 


#Shanghai exchange A

for i in {0..1999}; do
     stockId=`printf "6%05d" $i`	
     stockCode=$stockId".ss"
     wget `printf \"http://table.finance.yahoo.com/table.csv?s=%s\n\" $stockCode` -O $stockCode
      
     echo "
	load data
	INFILE '$stockCode'
	BADFILE '$stockCode.bad'
	DISCARDFILE '$stockCode.dis'
	INTO TABLE stockinfo
	APPEND
	FIELDS TERMINATED BY ',' 
	(stockdate date 'yyyy-mm-dd',
	 stockcode constant '$stockId',
	 open     ,
	 high     ,
	 low      ,
	 close     ,
	 volume    ,
	 adjclose   )
	" > $stockCode.ctl
    sqlldr userid=stock/stock@ORCL skip=1 control=$stockCode.ctl log=$stockCode.log
    rm $stockCode.ctl
    rm $stockCode.log
    rm $stockCode

    if [ -f '$stockCode.bad' ]; then
	  failedStock=$failedStock" "$stockCode
          echo $failedStock
    fi
    
done

 




